package com.beiding.jsonanalyzer.analyze.func.openfunc;

import com.beiding.jsonanalyzer.analyze.func.OneFunc;
import com.beiding.jsonanalyzer.analyze.func.base.EasyFunc;
import com.beiding.jsonanalyzer.analyze.func.base.OneFuncAdaptor;

/**
 * 日期格式化
 *
 * @author 丁常磊
 * @date 2022/5/19 11:23
 */

public class Trim {


    private Trim() {

    }

    public static OneFunc of(Object key) {
        return FuncUtils.buildForEasyFunc(new OneFuncAdaptor<EasyFunc>() {
            @Override
            protected EasyFunc newInstance() {
                return new EasyFunc() {

                    @Override
                    protected Object execute(Object v) {

                        if (v instanceof String) {
                            return ((String) v).trim();
                        }

                        return null;
                    }

                    @Override
                    public String toString() {
                            return "trim(" + core + ")";
                    }

                };
            }
        }, key);
    }

}
